
#ifndef __SPRITE_INSTANCE_H__
#define __SPRITE_INSTANCE_H__

#include "Core/Commons.h"
#include "Lib2D/Sprite.h"
//#include "Lib2D/Triangle.h"
#include "irrTypes.h"

class CSprite;

class CSpriteInstance
{
public:

	virtual void Update(float ts);
	virtual void Paint();
	virtual void Paint(const irr::core::vector3df& pos);

	static const irr::u32 FLAG_APPLY_ANIM_OFFSET	= 0x00020000;
	static const irr::u32 FLAG_HIDDEN			= 0x00040000;
	static const irr::u32 FLAG_PAUSED			= 0x00080000;
	static const irr::u32 FLAG_ALWAYS_PAINT		= 0x00100000;	
	static const irr::u32 FLAG_NO_ANIM_OFFSET	= 0x00200000;	


	CSprite*	m_pSpr;

	void InitInstance( irr::s32 posX, irr::s32 posY, CSprite* pSpr );

	CSpriteInstance();
	CSpriteInstance( irr::s32 posX, irr::s32 posY, CSprite* pSpr );
	~CSpriteInstance();

	void PaintAnim(int alpha = MAX_ALPHA);
	void PaintAnimOnScreen(int posX, int posY , int alpha = 255);
	void ApplyAnimOff();	
	void SetAnim(irr::s32 id);
	bool IsAnimEnded();
	//void SetScale(irr::f32 scale) { m_pSpr->SetScale(scale); };
	void SetScale(irr::f32 scale) { _fScale = scale; };
	void SetPosition(irr::s32 posX, irr::s32 posY);

	void SetAnimSafe(irr::s32 id);
	void Restart();

	int GetCrtTime() { return _nCrtTime; }
	int GetAnimation() { return _nCrtAnim; }
private:
	void UpdateSpriteAnim(float ts);
	void UpdateAnim(float ts);
private:
	irr::s16			_nCrtAnim;		// = _nCrtModule (if _nCrtTime < 0)
	irr::s16			_nCrtAFrame;	// = _nCrtFrame  (if _nCrtTime < 0)
	irr::s16			_nPrevAFrame;
	irr::s16			_nCrtTime;
	irr::u8				_nCrtPal;
	irr::u8				_nMap;
	irr::f32			_fScale;

	irr::s32				_posX;			// position
	irr::s32				_posY;

	irr::s32				_nOldX;
	irr::s32				_nOldY;

	irr::s32				_pos_ox;		// offset added to position
	irr::s32				_pos_oy;

	irr::u32				_flags;			// flags

	bool m_isEnded;


	float m_UpdateTime;
};

#endif //__SPRITE_INSTANCE_H__
